//
//  LCAllUserPostPulishItem.m
//  用卡圈
//
//  Created by MAC on 2018/12/6.
//  Copyright © 2018年 congliu. All rights reserved.
//

#import "LCAllUserPostPulishItem.h"

@interface LCAllUserPostPulishItem ()

@property (nonatomic,strong)UIButton *deleteBtn;

@property (nonatomic,strong)UIImageView *imageView;

@end

@implementation LCAllUserPostPulishItem

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self configSubView];
    }
    return self;
}

- (instancetype)initWithCollectionView:(UICollectionView *)collectionview forCellWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super init])
    {
        [collectionview registerClass:[LCAllUserPostPulishItem class] forCellWithReuseIdentifier:reuseIdentifier];
    }
    return self;
}

- (void)configSubView
{
    _imageView = [[UIImageView alloc]initWithFrame:CGRectZero];
    [self addSubview:_imageView];
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.height.width.equalTo(self).with.offset(-8.f);
    }];
    
    _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _deleteBtn.hidden = true;
    [_deleteBtn setImage:lc_image(@"loan_delete") forState:0];
    [_deleteBtn bk_addEventHandler:^(id sender) {
        
        if (self.delegate && [self.delegate respondsToSelector:@selector(deleteBtnClickAtIndexCell:)]) {
            [self.delegate deleteBtnClickAtIndexCell:self];
        }
        
    } forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_deleteBtn];
    [_deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_imageView).with.offset(-16.f);
        make.right.equalTo(_imageView).with.offset(16.f);
        make.height.width.mas_equalTo(32.f);
    }];
}

- (void)configData:(id)data showDeleteBtn:(BOOL)isShow
{
    UIImage *image = data;
    _imageView.image = image;
    _deleteBtn.hidden = !isShow;
}

@end
